window.onload = function() {
	Bmob.initialize("141d3c4c418aa624978d74a82375788b", "1764d1a85f20e649cb4bde39fdd70ebb");
    

    
	var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    if(isAndroid){
    	
    }else{
    	$("#info_div").attr('swiper-animate-effect','bounceIn')    	
    }

	var mySwiper = new Swiper('.swiper-container', {
		direction: 'vertical',		
		height: window.innerHeight,	
//		mousewheelControl: true,
//		paginationClickable: true,
//		watchSlidesProgress: true,
		lazyLoading : true,
//		loop: true,		
		// 如果需要分页器
		pagination: '.swiper-pagination',
		onInit: function(swiper) { //Swiper2.x的初始化是onFirstInit
			swiperAnimateCache(swiper); //隐藏动画元素 
			swiperAnimate(swiper); //初始化完成开始动画
		},
		onSlideChangeEnd: function(swiper) {
			swiperAnimate(swiper);
		},
		onTransitionEnd: function(swiper) {
			swiperAnimate(swiper);
			if(swiper.activeIndex==3){
				$("#bugTxt").show()
				$("#array").hide()
			}else{
				$("#array").show()
			}
			
		},
		
	})

$("#msg,#name,#count").focus(function(){	
	
	var w=window.innerWidth;
	w>320 ? $("#formWrap").css('top','-5%') : $("#formWrap").css('top','-10%')
	
	

}).blur(function(){
	window.setTimeout(function () { 
     if(isAndroid){
     	 document.scrollIntoViewIfNeeded()	
     	
     }else{
      document.activeElement.scrollIntoViewIfNeeded();  //弹出键盘时页面上移，键盘关闭后页面无法恢复正常，用这个方法可以恢复正常！！！
     	
     }
     
   	 
	}, 0);
	 $("#formWrap").css('top','10%')	

})


	var mySwiper3 = new Swiper('.swiper-container3',{
		effect : 'coverflow',		
		slidesPerView: 3,
		centeredSlides: true,
		coverflow: {
            rotate: 30,
            stretch: 5,
            depth: 60,
            modifier: 2,
            slideShadows : true
       },
       onTransitionStart:function(swiper){       	 
		  document.getElementById('sec').style.backgroundImage='url(img/photobg/photobg'+swiper.activeIndex+".jpg)";
         document.getElementById('secDivImg').setAttribute('class','')
         
       },
       onTransitionEnd: function(swiper){
         var index=swiper.activeIndex;       
         var name='url(img/invitation/smallImg'+index+".jpg)"
         var obj=document.getElementById('secDivImg')

         obj.setAttribute('class','openFadeIn')
		 obj.style.backgroundImage=name;	
           
         
	   
       }	
      
       
	})
   document.getElementById("swiper-container3").addEventListener('touchstart',function(e){
   	  document.getElementById('left_hander').style.display='none';
   	  
   })
   setInterval('countDown(2017,5,4,11,18,0)',1000)
}
$("#audio_btn").click(function(){
	if($(this).hasClass('rotate')){
		$(this).removeClass('rotate')
		$("#media")[0].pause()
	}else{
		$(this).addClass('rotate')
		$("#media")[0].play()
	}
})

//倒计时方法
function countDown(year,month,day,hour,minute,second){
	var countDown=(new Date(year,month,day,hour,minute,second))-(new Date());
	var days=parseInt(countDown/1000/60/60/24,10),
		hours=parseInt(countDown/1000/60/60%24,10),
		minutes=parseInt(countDown/1000/60%60,10),
		seconds=parseInt(countDown/1000%60,10);	
	days=checkTime(days);
	houts=checkTime(hours);
	minutes=checkTime(minutes);
	seconds=checkTime(seconds);	
	document.getElementById('countDown').innerHTML=days+'天'+hours+"时"+minutes+"分"+seconds+"秒"
}
//补零方法
function checkTime(i){
	return i=i<10 ? i='0'+i : i ;
}

//添加数据方法
function add(){
	
	//创建类和对象实例
	var people = Bmob.Object.extend("people");
	var name=$("#name").val(),count=$("#count").val(),msg=$("#msg").val();
	if(name=='' || count==''){
		showAlert('您需要填写姓名和来宾人数后才可提交哦',1500)
	}else{
		var person = new people();	
		person.save({
			name:name,
			count:count,
			msg:msg
		},{
			success:function(per){
				showAlert('谢谢，期待您的光临',1000)				
			},
			error:function(per,errData){
				console.log(errData.message)
			}
		})
	}
	
	
}

/*弹出层提示框*/
function showAlert(msg,time){	
	$("#myAlert").html(msg).show()
	setTimeout(function(){
		$("#myAlert").hide(time)
	},time)
}

$("#close").click(function(){
	$("#weather").hide()
})

/*查看天气*/
function seeWeather(){
 
  var script = document.createElement("script");
  script.src="http://api.map.baidu.com/telematics/v3/weather?location=天津市武清区&output=json&callback=getWeather&ak=180694f4c0d0d7429f7fefadd5e98e48"
  document.body.appendChild(script);
  document.body.removeChild(script)
  
  
   
}
/*接收百度api跨域请求来的数据*/
function getWeather(data){
	console.log(data)
	
	var hours=new Date().getHours();
	if(data.status=='success'){
		$("#wea_date").text(data.date);
		var items=data.results[0].weather_data;
		for(var i=0;i<items.length;i++){
			var str="<li class='wea_item'><div class='inlineBlock va_middle rightLine'>"+items[i].date+
					"</div><img class='wea_img inlineBlock  va_middle pl10' src="+ (hours<18? items[i].dayPictureUrl : items[i].nightPictureUrl)+
					"/><div class='inlineBlock va_middle rightLine pl10'>"+items[i].weather+
					"</div><div class='inlineBlock va_middle rightLine pl10'>"+items[i].temperature+
					"</div><div class='inlineBlock va_middle pl10'>"+items[i].wind+
					"</div></li>"
			$("#wea_content").append(str);
		}
	  $("#weather").show()
	}else{
		showAlert('请稍后重试',1500)
	}
}



